//
//  RegisteredView.m
//  豆瓣
//
//  Created by lanou3g on 15/12/9.
//  Copyright © 2015年 HaiTeng. All rights reserved.
//

#import "RegisteredView.h"

@implementation RegisteredView


- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];

    }
    
    return self;
    
}


- (void)addAllViews{
    
  
    
    //用户名
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.text = @"用户名:";
    [self addSubview:self.nameLabel];

    
    self.nameTF = [[UITextField alloc] init];
    self.nameTF.placeholder = @"请输入用户名";
    self.nameTF.borderStyle = UITextBorderStyleRoundedRect;
    self.nameTF.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.nameTF];

    
    
    //密码
    self.passwordLabel = [[UILabel alloc] init];
    self.passwordLabel.text = @"密码:";
    [self addSubview:self.passwordLabel];
    
    
    self.passwordTF = [[UITextField alloc] init];
    self.passwordTF.placeholder = @"请输入密码";
    self.passwordTF.borderStyle = UITextBorderStyleRoundedRect;
    self.passwordTF.clearButtonMode = UITextFieldViewModeAlways;
    self.passwordTF.secureTextEntry = YES;
    [self addSubview:self.passwordTF];
    
    
    
    //确认密码
    self.passwordLabelYES = [[UILabel alloc] init];
    self.passwordLabelYES.text = @"确认密码:";
    [self addSubview:self.passwordLabelYES];
    
    self.passwordTFYES = [[UITextField alloc] init];
    self.passwordTFYES.placeholder = @"再次确认密码";
    self.passwordTFYES.borderStyle = UITextBorderStyleRoundedRect;
    self.passwordTFYES.clearButtonMode = UITextFieldViewModeAlways;
    self.passwordTFYES.secureTextEntry = YES;
    [self addSubview:self.passwordTFYES];
    
    
    //手机号
    self.phoneNumberLabel = [[UILabel alloc] init];
    self.phoneNumberLabel.text = @"手机号:";
    [self addSubview:self.phoneNumberLabel];
    
    self.phoneNumberTF = [[UITextField alloc] init];
    self.phoneNumberTF.placeholder = @"请输入联系方式";
    self.phoneNumberTF.borderStyle = UITextBorderStyleRoundedRect;
    self.phoneNumberTF.clearButtonMode = UITextFieldViewModeAlways;
    self.phoneNumberTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    [self addSubview:self.phoneNumberTF];
    
    
    
    //邮箱
    self.emailLabel = [[UILabel alloc] init];
    self.emailLabel.text = @"邮箱:";
    [self addSubview:self.emailLabel];
    
    self.emailTF = [[UITextField alloc] init];
    self.emailTF.placeholder = @"请输入邮箱";
    self.emailTF.borderStyle = UITextBorderStyleRoundedRect;
    self.emailTF.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.emailTF];
    
    

    
    
}


//布局视图
- (void)layoutSubviews
{
    
    self.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height + 64);
    
    
    CGFloat w = self.frame.size.width / 13;
    
    self.nameLabel.frame = CGRectMake(w, w * 2, w * 3, 30);
    self.nameTF.frame = CGRectMake(CGRectGetMaxX(self.nameLabel.frame) + w, w * 2, w * 7, 30);
    
    
    
    self.passwordLabel.frame = CGRectMake(w, CGRectGetMaxY(self.nameLabel.frame) + w, w * 3, 30);
    
   self.passwordTF.frame = CGRectMake(CGRectGetMaxX(self.nameLabel.frame) + w, CGRectGetMaxY(self.nameTF.frame) + w, w * 7, 30);
    
    
    
    self.passwordLabelYES.frame = CGRectMake(w, CGRectGetMaxY(self.passwordLabel.frame) + w, w * 3, 30);
    
    self.passwordTFYES.frame = CGRectMake(CGRectGetMaxX(self.passwordLabel.frame) + w, CGRectGetMaxY(self.passwordTF.frame) + w, w * 7, 30);
    
    
    
    self.phoneNumberLabel.frame = CGRectMake(w, CGRectGetMaxY(self.passwordLabelYES.frame) + w, w * 3, 30);
    
    self.phoneNumberTF.frame = CGRectMake(CGRectGetMaxX(self.passwordLabelYES.frame) + w, CGRectGetMaxY(self.passwordTFYES.frame) + w, w * 7, 30);
    
    
    
    self.emailLabel.frame = CGRectMake(w, CGRectGetMaxY(self.phoneNumberLabel.frame) + w, w * 3, 30);
    
    self.emailTF.frame = CGRectMake(CGRectGetMaxX(self.phoneNumberLabel.frame) + w, CGRectGetMaxY(self.phoneNumberTF.frame) + w, w * 7, 30);
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self endEditing:YES];
}


@end
